package com.oa.official.common.component;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.support.PropertySourceFactory;
import org.springframework.stereotype.Component;

/**
 * minio的基本连接配置信息
 */
@Data
@Component
@ConfigurationProperties(prefix = "minio.client")
@PropertySource(
        value = {"classpath:application-minio.yaml"},
        encoding = "utf-8",
        ignoreResourceNotFound = true)
public class MinioConfig {

    /**
     * minio服务端地址URL ip+port
     */
    private String endpoint;
    /**
     * 认证的key,相当于用户名
     */
    private String accessKey;
    /**
     * 秘钥，相当于密码
     */
    private String secretAccessKey;

    /**
     * 创建minio连接客户端对象
     * @return
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretAccessKey)
                .build();
    }
}
